<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<link rel="stylesheet" href="css/listCommon.css" />
<style>
	.modal-backdrop {
		position: inherit;
	}
	.btn.focus, .btn:focus, .btn:hover {
		color: #333;
		background: white;
		border: 1px solid #e7eaec;
	}
	#setMoney .modal-content{
		margin-top:100px;
	}
	#setMoney .modal-dialog{
		width:600px !important;
	}
	#setMoney .col-md-12 label{display: inline-block;width:80px;}
	#setMoney .col-md-12 input{display: inline-block;width:470px;}
	#setMoney .modal-body {
		padding: 20px 0 30px 0;
	}
</style>
<jsp:include page="../common/nav.jsp"></jsp:include>
<div class="wrapper wrapper-content animated fadeInRight">
	<jsp:include page="search.jsp"></jsp:include>
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
		        <div class="ibox-title">
		            <h4>采购订单列表</h4>
		            <div class="ibox-tools">
		                <button id="searchButton" class="btn btn-default btn-sm btn-notcontrol" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
		            </div>
		        </div>
				<div class="ibox-content border-bottom" style="padding-bottom: 0;">
					<div class="table-responsive">
						<table class="table table-striped table-hover table-bordered border-top">
							<thead>
								<tr>
									<th width="5%">序号</th>
									<th>编号</th>
									<th>公司</th>
									<th>供应商</th>
									<th>订单金额</th>
									<th>已付金额</th>
									<th>联系人</th>
									<th>联系电话</th>
									<th>收货时间</th>
									<th>收货地址</th>
									<th>状态</th>
									<th width="10%">操作</th>
								</tr>
							</thead>
							<tbody>
							    <c:forEach items="${requestScope.list}" var="data" varStatus="index">
									<tr>
										<td>${index.count}</td>
										<td>${data.code}</td>
										<td>${data.companyName}</td>
										<td>${data.supplierName}</td>
										<td>${data.totalMoney}</td>
										<td>${data.amountPaid}</td>
										<td>${data.linkman}</td>
										<td>${data.tel}</td>
										<td>${data.beginDate.concat(' 至 '.concat(data.endDate))}</td>
										<td>${data.address}</td>
										<td>${requestScope.statusMap[data.status]}</td>
										<td>
											<div class="btn-group">
												<c:if test="${'0' eq data.status}">
													<button class="btn-white btn btn-xs btn-notcontrol"  onclick="show('${data.id}', ${data.totalMoney})"><i class="fa fa-eye"></i>&nbsp;设置金额</button>&nbsp;
													<button class="btn-white btn btn-xs btn-notcontrol" onclick="submitData('${data.id}')"><i class="fa fa-eye"></i>&nbsp;下单</button>&nbsp;
												</c:if>
												<button class="btn-white btn btn-xs btn-notcontrol" onclick="showData('${data.id}')"><i class="fa fa-eye"></i>&nbsp;查看</button>&nbsp;
											</div>
										</td>
									</tr>
								</c:forEach>
							</tbody>
							<tfoot>
							<jsp:include page="../common/pages.jsp"></jsp:include>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="setMoney" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content" style="padding: 0 20px">
			<div class="modal-header">
				<h4 class="modal-title" id="myModalLabel">设置订单金额</h4>
			</div>
			<div class="modal-body">
				<div class="row">
					<input id="id" type="hidden">
					<div class="col-md-12">
						<label>订单金额：</label>
						<input id="money" type="number" class="form-control" placeholder="请输入订单金额">
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="setMoney()">保存</button>
				<button type="button" class="btn btn-default" onclick="closePopout();">关闭</button>
			</div>
		</div>
	</div>
</div>
<script src="js/listPage.js"></script>
<script>
	// 显示弹框
	function show(id, money) {
		$("#id").val(id);
		$("#money").val(money);
		$("#setMoney").modal('show');
	}

	// 设置订单金额
	function setMoney() {
		let money = $("#money").val();
		if (money === "") {
			redragonJS.alert("订单金额不能为空!");
			return;
		} else if (money < 0) {
			redragonJS.alert("订单金额不能为负数!");
			return;
		} else if (money === "0") {
			redragonJS.alert("订单金额不能为0!");
			return;
		}
		$.ajax({
			type: "post",
			url: "web/purchaseOrder/setMoney",
			data: {
				id: $("#id").val(),
				totalMoney: money
			},
			dataType: "json",
			async: false,
			success: function (data) {
				debugger
				if(data.code == 1) {
					redragonJS.alert("设置成功");
					setTimeout(function(){
						window.location.href='web/purchaseOrder/getPageList'
					},1000);
				} else {
					redragonJS.alert(data.msg);
				}
			}
		});
	}

	// 清除数据
	function closePopout() {
		$("#id").val("");
		$("#money").val("");
		$("#setMoney").modal('hide').removeClass("show");
	}

	// 提交订单
	function submitData(id) {
		$.ajax({
			type: "post",
			url: "web/purchaseOrder/changeStatus",
			data: {
				id: id
			},
			dataType: "json",
			async: false,
			success: function (data) {
				if(data.code == 1) {
					redragonJS.alert("提交成功");
					setTimeout(function(){
						window.location.href='web/purchaseOrder/getPageList'
					},1000);
				} else {
					redragonJS.alert(data.msg);
				}
			}
		});
	}

	// 查看
	function showData(id) {
		window.location.href="web/purchaseOrder/detail?id=" + id;
	}
</script>